home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / MAKEKEY2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  6KB  |  147 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to create *)
  4. (* an encrypted registration-key using "embedded" encryption-codes.   *)
  5. (*                                                                    *)
  6. (* NOTE: Before you can compile this program, you must first          *)
  7. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  8. (*       the two "random" encryption-code binary data files. Then     *)
  9. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  10. (*       these two binary data files to "object" format files.        *)
  11. (**********************************************************************)
  12.  
  13. program MakeFlxKeyDemo2;
  14. uses
  15.   FlxKey;
  16.  
  17. type
  18.               (* 20 character string-pointer definition.              *)
  19.   st_20Ptr = ^st_20;
  20.  
  21. var           (* This variable is used to check for errors returned   *)
  22.               (* by CreateFlxKey routine.                             *)
  23.   ErrorCode  : word;
  24.  
  25.               (* 2 encryption-code string-pointers.                   *)
  26.   Ecode1Ptr,
  27.   Ecode2Ptr  : st_20Ptr;
  28.  
  29.               (* Full path/filename of the encrypted registration-key *)
  30.               (* file to be created.                                  *)
  31.   RegKeyName : st_79;
  32.  
  33.               (* This variable is used to pass the user-data to the   *)
  34.               (* CreateFlxKey routine.                                *)
  35.   TempKeyRec : rc_Flx;
  36.  
  37.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  38.  
  39.               (* "Fake" procedure that contains first encryption-code *)
  40.               (* string.                                              *)
  41.   procedure Ecode1Data; external;
  42.   {$L ECODE1.OBJ}
  43.  
  44.               (* "Fake" procedure that contains second encryption-    *)
  45.               (* code string.                                         *)
  46.   procedure Ecode2Data; external;
  47.   {$L ECODE2.OBJ}
  48.  
  49.   {$F-}       (* Turn off "FAR" declaration.                          *)
  50.  
  51.               (* Main program execution block.                        *)
  52. BEGIN
  53.               (* Initialize the encryption-code pointers to their     *)
  54.               (* string data.                                         *)
  55.   Ecode1ptr := addr(Ecode1Data);
  56.   Ecode2ptr := addr(Ecode2Data);
  57.  
  58.               (* Clear the temporary key-record variable.             *)
  59.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  60.  
  61.               (* Assign data to temporary key-record.                 *)
  62.   with TempKeyRec do
  63.     begin
  64.               (* 20 char space is available for first-name.           *)
  65.       FirstName := 'John';
  66.  
  67.               (* 30 char space is available for last-name.            *)
  68.       LastName  := 'Smith';
  69.  
  70.               (* 30 char space is available for Address1.             *)
  71.       Address1  := '1234 AnyPlace Road,';
  72.  
  73.               (* 30 char space is available for Address2.             *)
  74.       Address2  := 'BigCity BigPlace,';
  75.  
  76.               (* 30 char space is available for Address3.             *)
  77.       Address3  := 'BigCountry, BigZip';
  78.  
  79.               (* 20 char space is available for application-name.     *)
  80.       AppName   := 'Amazing Program';
  81.  
  82.               (* Version can be assigned any valid word data.         *)
  83.       Version   := 310;
  84.  
  85.               (* Serial can be assigned any valid longint data.       *)
  86.       Serial    := 1234567890;
  87.  
  88.               (* Date can be assigned any valid "packed" date/time.   *)
  89.               (* If a value of 0 is assigned to Date, CreateFlxKey    *)
  90.               (* routine will assign the current date/time to this    *)
  91.               (* variable in "packed" date/time format. Use TP's      *)
  92.               (* standard "PackTime" and "UnPackTime" routines to     *)
  93.               (* manipulate this data.                                *)
  94.       Date      := 0;
  95.  
  96.               (* Access level can be assigned a number from 0..65,535 *)
  97.       Access    := 1234;
  98.  
  99.       MiscData  := 'You can place what ever sort of data you like' +
  100.                    #13#10 + '                within this field, ' +
  101.                    'upto 254 bytes worth.'
  102.     end;
  103.  
  104.               (* Filename for the encrypted registration-key to be    *)
  105.               (* created.                                             *)
  106.   RegKeyName := 'DEMO2.KEY';
  107.  
  108.               (* Create encrypted registration-key using the data     *)
  109.               (* assigned to TempKeyRec.                              *)
  110.   CreateFlxKey(TempKeyRec, Ecode1Ptr^, Ecode2Ptr^, RegKeyName, ErrorCode);
  111.  
  112.               (* Move cursor down one line.                           *)
  113.   writeln;
  114.  
  115.               (* Check for errors.                                    *)
  116.   case (ErrorCode AND $FF) of
  117.      0 : writeln(' Sucessful key creation! No errors.');
  118.      1 : writeln(' Error! One or more encryption-codes is blank.');
  119.      2 : writeln(' Error! Filename for registration-key file is blank.');
  120.      3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  121.                  'buffer.');
  122.      4 : writeln(' BlocWrite error.');
  123.      5 : writeln(' BlockRead error.');
  124.      6 : writeln(' Date error. PC''s system date pre-dates ' +
  125.                  'registration-key date.');
  126.      7 : writeln(' Registration-key is corrupt.');
  127.  
  128.               (* I/O error!                                           *)
  129.     16 : begin
  130.            writeln(' I/O error = ', (ErrorCode shr 8));
  131.  
  132.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  133.               (* as there are many types of errors to check for.      *)
  134.            case (ErrorCode shr 8) of
  135.                2 : writeln(' File not found.');
  136.                3 : writeln(' Path not found.');
  137.                4 : writeln(' Too many files open.');
  138.                5 : writeln(' File access denied.');
  139.              101 : writeln(' Disk write error.');
  140.              103 : writeln(' File not open');
  141.              150 : writeln(' Disk is write-protected')
  142.            end  (* case (ErrorCode shr 8) of                          *)
  143.          end
  144.   end         (* case (ErrorCode AND $FF) of                          *)
  145. END.
  146.  
  147.